<?php

require('init.php');

if ( isset($_REQUEST['accept_denny']) ){
	if( $_REQUEST['accept_denny'] == 1 ){
		$con = $DB->q('TUPLE SELECT * FROM solic_account WHERE login = %s',$_REQUEST['id']);
		$DB->q('INSERT INTO team( login, name, categoryid, members, email) 
			VALUES( %s, %s, %i, %s, %s )',$con['login'], $con['name'], $con['categoryid'],
			 $con['members'], $con['email'] );
		$DB->q('UPDATE solic_account SET answer = 1 WHERE login = %s', $_REQUEST['id']);
		
	}else{
		$DB->q('UPDATE solic_account SET answer = 0 WHERE login = %s', $_REQUEST['id']);	
	}
}else{
	echo "Variable no definida";
}







require(LIBWWWDIR . '/header.php');
require(LIBWWWDIR . '/forms.php');



echo "<h1>Postmaraton Account Requests</h1>\n\n";

$conexion = connect();
$query = "SELECT COUNT(*) FROM solic_account ";
$res = mysql_query($query, $conexion) or die(mysql_error());
$registers = mysql_result($res, 0);

if ( $registers == 0){
	echo "<p class=\"nodata\">No account request received yet</p>\n\n";
}else{
	$q = "SELECT * FROM solic_account WHERE answer IS NULL ";
	$answ = mysql_query($q, $conexion) or die(mysql_error());
	echo mysql_num_rows($answ);
	
	echo "<table class=\"list sortable\">\n<thead>\n" .
		"<tr><th scope=\"col\">Date</th>" .
		"<th scope=\"col\">Name</th>" .	
		"<th scope=\"col\">Email</th>" .
		"<th scope=\"col\">Answer</th>" .
		"</tr></thead>\n<tbody>\n"; 
	
	while ( $row = mysql_fetch_array($answ) ){
		//$link = '<a href="request.php?id='.htmlspecialchars($row['login']).'">';
		echo '<tr><td>'.htmlspecialchars($row['date']).'</td><td>'.
			htmlspecialchars($row['name']).'</td><td>'.
			htmlspecialchars($row['email']).'</td>'.
		'<td><form action="requests.php?id='.htmlspecialchars($row['login']).'" method="post">'.
		//<form id="form" action="adduser.php" method="post" accept-charset="UTF-8">
			addRadioButton('accept_denny','', 1).
		'<label for="accept">Accept</label>'.
			addRadioButton('accept_denny','', 0).'<label for="denny">Denny</label>'.
		addSubmit('Save').'</td></form>';		
	}
	echo '</table>';
}

/*
FALTA ADICIONAR: ENVIO DE RESPUESTA A TRAVÉS DEL CORREO
 */

?>

